package com.guigu.buy.controller;

import com.github.pagehelper.PageInfo;
import com.guigu.buy.dto.PurOrder_Details;
import com.guigu.buy.dto.PurOrder_Supplier;
import com.guigu.buy.mapper.PurchaseOrderMapper;
import com.guigu.buy.pojo.PurchaseOrder;
import com.guigu.buy.service.IPurchaseOrderService;
import com.guigu.buy.utils.FileAddUtil;
import com.guigu.buy.vo.PurAllVo;
import com.guigu.buy.vo.PurOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@CrossOrigin
@Controller
@RequestMapping("/buy/purchaseOrder")
public class PurchaseOrderController {
    @Autowired
    private IPurchaseOrderService purchaseOrderService;
    @Autowired
    private FileAddUtil addUtil;

    //添加采购单及详情
    @RequestMapping("/addOrder")
    @ResponseBody
    public String  addOrder(@RequestBody PurOrder_Details purOrder_details){
        if(purchaseOrderService.add(purOrder_details,addUtil.getTypeNumber("100"))){
            return "ok";
        }
        return "no";
    }
    //查询采购单
    @RequestMapping("/selPurOrder/{pageSize}/{pageNo}")
    @ResponseBody
    public PageInfo<PurOrder_Supplier> selPurOrder(@PathVariable int pageSize,
                                                   @PathVariable int pageNo,
                                                   @RequestBody PurOrderVo vo){
        return purchaseOrderService.selPurOrder(pageNo,pageSize,vo);
    }
    //采购单回显
    @RequestMapping("/getOne/{id}")
    @ResponseBody
    public PurchaseOrder getOne(@PathVariable int id){
        return purchaseOrderService.getById(id);
    }
    //采购单审核
    @RequestMapping("/auditPur")
    @ResponseBody
    public boolean audit(@RequestBody PurchaseOrder purchaseOrder){
           return purchaseOrderService.updateById(purchaseOrder);
    }
    //查询所有采购单
    @RequestMapping("/queryAll/{pageSize}/{pageNo}")
    @ResponseBody
    public PageInfo<PurOrder_Supplier> queryAll(@PathVariable int pageSize,
                                                @PathVariable int pageNo,
                                                @RequestBody PurAllVo vo){
            return purchaseOrderService.queryAll(pageNo,pageSize,vo);
    }

    //查询采购订单表

    @RequestMapping("/page/{pageSize}/{pageNo}/{id}")
    @ResponseBody
    public PageInfo<PurchaseOrder> page(@PathVariable int id,
                                        @PathVariable int pageSize,
                                        @PathVariable int pageNo
    ) {
        return purchaseOrderService.page(id, pageNo, pageSize);
    }

    //根据订单编号查询详情采购单发货

    @RequestMapping("/shipments/{id}")
    @ResponseBody
    public String shipments(@PathVariable int id) {
        PurchaseOrder purchaseOrder=new PurchaseOrder();
        purchaseOrder.setConveyTag("P001-2");
        purchaseOrder.setId(id);
        boolean flag = this.purchaseOrderService.updateById(purchaseOrder);
        if (flag) {

            return "ok";
        }
        return "error";
    }

}
